from selenium import webdriver
from selenium.webdriver.common.by import By

#打开谷歌,打开so浏览器
driver = webdriver.Chrome()
driver.get("https://www.sogou.com/")
#
# #标签加属性
kw =driver.find_element(By.CSS_SELECTOR, '#query') #通过id定位
sec =driver.find_element(By.CSS_SELECTOR, '.sec-input') #通过class定位
name =driver.find_element(By.CSS_SELECTOR, "input[name='query']") #通过name定位
#通过层级定位
names=driver.find_element(By.CSS_SELECTOR, "input[name='query']")
print(kw.get_attribute('outerHTML'))
print(sec.get_attribute('outerHTML'))
print(name.get_attribute('outerHTML'))
print(names.get_attribute('outerHTML'))
#
# #通过索引
print(driver.find_element(By.CSS_SELECTOR, "from[id='sf'] input:nth-child(6)").get_attribute('outerHTML'))
# #通过模糊关键字寻找
print(driver.find_element(By.CSS_SELECTOR, "input[name*='_idx']").get_attribute("outerHTML"))

# 多条件查找
print(driver.find_element(By.CSS_SELECTOR, "input[name='wd'][autocomplete='off']").get_attribute("outerHTML"))

driver.quit()